package services;

import java.util.*;
import models.*;
import models.mappers.*;
import voidlib.*;

/**
 * @author nevidimov
 */
public class MoneyService {
    public static boolean transferMoney(int fromUser, int toUser, int amount) {
        User from = new User().fetch(fromUser);
        User to = new User().fetch(toUser);
        if (from.getBalance() < amount) {
            VoidController.setMessage("User " + from.getTitle() +" has not enough money.");
            return false;
        }
        from._balance -= amount;
        to._balance += amount;
        from.save();;
        to.save();
        return true;
    }
}
